package com.example.mr5.money.main.myincome;/**
 * Created by Mr.5
 * Date：2016/9/29.
 * Time：18:50
 */

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.mr5.money.R;
import com.example.mr5.money.model.CommonType;

import java.util.List;

/**
 * Created by Mr.5 
 * Date：2016/9/29.
 * Time：18:50
 */
public class FilterGridViewAdapter extends BaseAdapter {

    private Context context;
    private List<CommonType> filterList;

    public FilterGridViewAdapter(Context context,List<CommonType> list){
        this.context = context;
        this.filterList = list;
    }

    @Override
    public int getCount() {
        return filterList.size();
    }

    @Override
    public Object getItem(int position) {
        return filterList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null){
            holder = new ViewHolder();
            convertView = View.inflate(context,R.layout.item_filter_grid_view,null);
            holder.filterTitle = (TextView) convertView.findViewById(R.id.filter_title);
            holder.bgFilter = (LinearLayout) convertView.findViewById(R.id.bg_filter);
            holder.checkBox = (CheckBox) convertView.findViewById(R.id.filter_check_box);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.filterTitle.setText(filterList.get(position).getName());
        if (filterList.get(position).isCheck()){
            holder.filterTitle.setTextColor(context.getResources().getColor(R.color.money_red));
            holder.bgFilter.setBackground(context.getResources().getDrawable(R.drawable.radius_text_view_bg_selected));
        }else {
            holder.filterTitle.setTextColor(context.getResources().getColor(R.color.money_gray_text));
            holder.bgFilter.setBackground(context.getResources().getDrawable(R.drawable.radius_text_view_bg_unselected));
        }
        return convertView;
    }

    private class ViewHolder{
        private TextView filterTitle;
        private LinearLayout bgFilter;
        private CheckBox checkBox;
    }
}
